<template>
    <span v-html="userInfo"> </span>
</template>

<script>
    import Api from '@/api/Api.js';

    export default {
        name: "rx-user-info",
        props: {
            userId: {type: String},
            showAccount: {
                type: Boolean,
                default: false
            }
        },
        data() {
            return {userInfo: ""}
        },
        created() {
            if (this.userId) {
                this.loadUser();
            }
        },
        methods: {
            loadUser() {
                Api.getUserInfo(this.userId).then(res => {
                    this.userInfo = res.fullName
                    if (this.showAccount) {
                        this.userInfo += "[" + res.userNo + "]";
                    }
                })
            }
        },
        watch: {
            userId: function (val) {
                if (val) {
                    this.loadUser();
                }
            }
        }

    }
</script>

<style scoped>

</style>
